package com.dq.controller.api.merchant.workbench.customer;
import com.dq.exception.customException.AdminException;
import com.dq.controller.in.CusServiceQuery;
import com.dq.vo.Vo;
import com.dq.domain.record.ServiceRecord;
import com.dq.service.AllService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author liuhui
 * @date 2019/11/23 0023 14:21:31
 */
@RestController
@RequestMapping("/api/merchant/workbench/customer/service")
@Api(description = "服务")
public class CusServiceController extends AllService {


    @PostMapping("/list")
    @ApiOperation("多条件检索顾客服务记录")
    public Vo list(@RequestBody CusServiceQuery cusServiceQuery)throws AdminException {

        List<ServiceRecord> list = cusServicesService.list(cusServiceQuery);
        Long count = cusServicesService.count(cusServiceQuery);

        List<ServiceRecord.OrgUserServiceRecordVo> orgUserServiceRecordVos = new ArrayList<>();
        list.forEach(ServiceRecord ->{
            orgUserServiceRecordVos.add(ServiceRecord.toOrgUserServiceRecordVo());
        });
        PageInfo pageInfo = new PageInfo(orgUserServiceRecordVos);
        pageInfo.setTotal(count);
        return new Vo(pageInfo);
    }
    
}
